<%--
  Created by IntelliJ IDEA.
  User: 494418174
  Date: 2020/3/6 0006
  Time: 10:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/layui_ext/dtree/dtree.css">
    <link rel="stylesheet" href="/layui_ext/dtree/font/dtreefont.css">
</head>
<body class="childrenBody">
<!-- 搜索条件开始 -->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>查询条件</legend>
</fieldset>
<form class="layui-form" method="post" id="searchFrm">

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">订单号:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="rentId" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入订单号" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">身份证号:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="identity" autocomplete="off" class="layui-input layui-input-inline"
                       placeholder="请输入身份证号" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">出租时间:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="beginDate" id="beginDate" autocomplete="off"
                       class="layui-input layui-input-inline"
                       placeholder="请输入出租时间" style="height: 30px;border-radius: 10px">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">归还时间:</label>
            <div class="layui-input-inline" style="padding: 5px">
                <input type="text" name="returnDate" id="returnDate" autocomplete="off"
                       class="layui-input layui-input-inline"
                       placeholder="请输入归还时间" style="height: 30px;border-radius: 10px">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">是否归还:</label>
            <div class="layui-input-inline">
                <input type="radio" name="rentFlag" value="1" title="已归还">
                <input type="radio" name="rentFlag" value="0" title="未归还">
            </div>
            <button type="button"
                    class="layui-btn layui-btn-normal layui-icon layui-icon-search layui-btn-radius layui-btn-sm"
                    lay-submit lay-filter="formDemo" style="margin-top: 4px">查询
            </button>
            <button type="reset"
                    class="layui-btn layui-btn-warm layui-icon layui-icon-refresh layui-btn-radius layui-btn-sm"
                    style="margin-top: 4px">重置
            </button>
        </div>
    </div>

</form>

<!-- 搜索条件结束 -->

<table id="rentTable" lay-filter="rentTable"></table>


<script id="barRent" type="text/html">

     {{#  if(d.rentFlag == 0){ }}
     <a class="layui-btn layui-btn-xs layui-btn-radius" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs " lay-event="del">删除</a>
        {{#  }else{ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs " lay-event="rentExcel">出租单导出</a>
    {{# }}}
</script>


<!-- 添加和修改的弹出层-->
<div style="display: none;padding: 20px" id="saveOrUpdateDiv">
    <form class="layui-form layui-row layui-col-space10" lay-filter="dataFrm" id="dataFrm">
        <div class="layui-col-md12 layui-col-xs12">
            <div class="layui-row layui-col-space10">
                <div class="layui-col-md9 layui-col-xs7">

                    <div class="layui-form-item magt3">
                        <label class="layui-form-label">订单号:</label>
                        <div class="layui-input-block" style="padding: 5px">
                            <input type="text" name="rentId" id="rentId" autocomplete="off" class="layui-input"
                                   lay-verify="required"
                                   placeholder="请输入订单号" style="height: 30px;border-radius: 10px">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">出租价格:</label>
                        <div class="layui-input-block" style="padding: 5px">
                            <input type="text" name="price" autocomplete="off" class="layui-input"
                                   lay-verify="required|number"
                                   placeholder="请输入出租价格" style="height: 30px;border-radius: 10px">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">出租时间:</label>
                        <div class="layui-input-block" style="padding: 5px">
                            <input type="text" name="beginDate" id="beginDate1" autocomplete="off" class="layui-input"
                                   placeholder="请输入出租时间" style="height: 30px;border-radius: 10px;width: 250px">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item magb0">
                <label class="layui-form-label">归还时间:</label>
                <div class="layui-input-block" style="padding: 5px">
                    <input type="text" name="returnDate" id="returnDate1" autocomplete="off" class="layui-input"
                           placeholder="请输入归还时间" style="height: 30px;border-radius: 10px;width: 250px">
                </div>
            </div>
            <div class="layui-form-item magb0">
                <div class="layui-inline">
                    <label class="layui-form-label">身份证号:</label>
                    <div class="layui-input-block" style="padding: 5px">
                        <input type="text" name="identity" class="layui-input"
                               placeholder="请输入身份证号" style="height: 30px;border-radius: 10px">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">车牌号:</label>
                    <div class="layui-input-block" style="padding: 5px">
                        <input type="text" name="carNumber" class="layui-input"
                               placeholder="请输入车牌号" style="height: 30px;border-radius: 10px">
                    </div>
                </div>
            </div>
            <div class="layui-form-item magb0">
                <div class="layui-inline">
                    <label class="layui-form-label">操作人:</label>
                    <div class="layui-input-block" style="padding: 5px">
                        <input type="text" name="openName" class="layui-input"
                               placeholder="请输入操作人" style="height: 30px;border-radius: 10px">
                    </div>
                </div>
            </div>
            <div class="layui-form-item magb0">
                <div class="layui-input-block" style="text-align: center;padding-right: 120px">
                    <button type="button"
                            class="layui-btn layui-btn-normal layui-btn-md layui-icon layui-icon-release layui-btn-radius"
                            lay-filter="doSubmit" lay-submit="">提交
                    </button>
                    <button type="reset"
                            class="layui-btn layui-btn-warm layui-btn-md layui-icon layui-icon-refresh layui-btn-radius">
                        重置
                    </button>
                </div>
            </div>
        </div>
    </form>
</div>
<%-- 添加或者修改弹出框结束 --%>

<script src="/layui/layui.js"></script>
<script>
    var rentTable
    var index
    var url
    var uploadImg
    layui.extend({
        dtree: '/layui_ext/dtree/dtree'   // {/}的意思即代表采用自有路径，即不跟随 base 路径
    }).use(['table', 'form', 'layer', 'jquery', 'laydate'], function () {
        var table = layui.table
        var form = layui.form
        var layer = layui.layer
        var $ = layui.jquery
        var laydate = layui.laydate
        laydate.render({
            elem: '#beginDate'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#returnDate'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#beginDate1'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#returnDate1'
            , type: 'datetime'
        });

        // 初始table
        rentTable = table.render({
            elem: "#rentTable"
            , url: "/rent/findRent"
            , page: {limit: 5, limits: [5, 10, 15]}
            , cellMinWidth: 80
            , cols: [[ //表头
                {field: 'rentId', title: '订单号', fixed: 'center'}
                , {field: 'price', title: '出租价格', fixed: 'center'}
                , {field: 'beginDate', title: '出租时间', fixed: 'center'}
                , {field: 'returnDate', title: '归还时间', fixed: 'center'}
                , {field: 'identity', title: '身份证号', fixed: 'center'}
                , {field: 'carNumber', title: '车牌号', fixed: 'center'}
                , {
                    field: 'rentFlag', title: '是否归还', fixed: 'center', templet: function (d) {
                        return d.rentFlag == 1 ? "已归还" : "未归还"
                    }
                }
                , {field: 'openName', title: '操作人', fixed: 'center'}
                , {field: 'createTime', title: '创建时间', fixed: 'center'}
                , {fixed: 'right', title: '操作', toolbar: '#barRent', width: 125}
            ]]
        })

        // 查询
        form.on("submit(formDemo)", function (data) {
            rentTable.reload({
                url: "/rent/findRent"
                , where: {
                    'rentId': data.field.rentId
                    , 'beginDate': data.field.beginDate
                    , 'returnDate': data.field.returnDate
                    , 'identity': data.field.identity
                    , 'rentFlag': data.field.rentFlag

                }
                , page: {
                    curr: 1
                }
            })
            return false;
        })

        //监听行工具事件
        table.on('tool(rentTable)', function (obj) {
            var data = obj.data
            if (obj.event == "edit") {
                menuUpdate(data)
            } else if (obj.event == "del") {
                del(data)
            }else if(obj.event=="rentExcel"){
                location.href="/rent/rentExcel?rentId="+data.rentId
            }
        })

        function del(data) {


            layer.confirm("您确定要删除出租单数据么?", function (ind) {

                $.post("/rent/delRent", {"rentId": data.rentId}, function (d) {
                    layer.msg(d.msg)
                    // 刷新table数据
                    rentTable.reload()

                })
                layer.close(ind)
            })


        }

        function menuUpdate(data) {
            index = layer.open({
                type: 1
                , title: "修改出租单"
                , content: $("#saveOrUpdateDiv")
                , area: ['800px', '440px']
                , success: function (layero, index) {
                    form.val("dataFrm", data)
                    url = "/rent/updateRent"
                }
            })
        }

        // form表达提交
        form.on("submit(doSubmit)", function () {
            layer.confirm("您确定要提交该数据么", function (ind) {
                $.post(url, $("#dataFrm").serialize(), function (data) {
                    layer.msg(data.msg)
                    layer.close(index)
                    rentTable.reload()
                })
                layer.close(ind)
            })


        })
    })

</script>
</body>
</html>
